package vn.co.thn.android.videohot.fragment;

import vn.co.thn.android.videohot.R;
import vn.co.thn.android.videohot.adapter.VHTimeLinePagerAdapter;
import vn.co.thn.android.videohot.common.VHCommonFragment;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class VHTimeLineFragment extends VHCommonFragment implements OnPageChangeListener {
	private ViewPager viewpager;
	private VHTimeLinePagerAdapter mListTimeLine;
	private int mCurrentPage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	public static VHTimeLineFragment getInstance() {
		VHTimeLineFragment fragment = new VHTimeLineFragment();
		return fragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.vh_timeline_fragment, container, false);
		viewpager = (ViewPager) view.findViewById(R.id.vp_timeline);
		viewpager.setOnPageChangeListener(this);
		return view;
	}

	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		mListTimeLine = new VHTimeLinePagerAdapter(getChildFragmentManager(), getActivity());
		viewpager.setAdapter(mListTimeLine);

	}

	@Override
	public void onDataRefresh() {
		((VHCommonFragment)mListTimeLine.getItem(mCurrentPage)).onDataRefresh();
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {

	}

	@Override
	public void onPageSelected(int arg0) {
		mCurrentPage=arg0;
		((VHCommonFragment)mListTimeLine.getItem(mCurrentPage)).onDataRefresh();
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
	}

	@Override
	public void onDetach() {
		// TODO Auto-generated method stub
		super.onDetach();
	}
}
